#!/usr/bin/env python3
#coding=utf8

import os

import tornado.ioloop
import tornado.web
from tornado.httpserver import HTTPServer
from tornado.options import define, options, parse_command_line

from core import handler

SETTINGS = {
    "debug"         : True,
    "template_path" : os.path.join(os.path.dirname(__file__), 'templates'),
    "static_path"   : os.path.join(os.path.dirname(__file__), "static"),
    "login_url"     : "/login",
    "cookie_secret" : "{[ni]+[si]-[01]*[ge]/[da]=[sa]%[bi]}",
}

URLS = [
] + handler.Route.routes()

class Application(tornado.web.Application):
    def __init__(self):
        tornado.web.Application.__init__(self, handlers=URLS, **SETTINGS)

def main():
    App = HTTPServer(Application(), xheaders=True)
    App.listen(options.port)
    loop = tornado.ioloop.IOLoop.instance()
    loop.start()

if __name__ == '__main__':
    define('port', default=8315, type=int)
    parse_command_line()
    main()